package com.ms3ds.deviceData.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ms3ds.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ms3ds.common.log.annotation.Log;
import com.ms3ds.common.log.enums.BusinessType;
import com.ms3ds.common.security.annotation.RequiresPermissions;
import com.ms3ds.deviceData.domain.Footage;
import com.ms3ds.deviceData.service.IFootageService;
import com.ms3ds.common.core.web.controller.BaseController;
import com.ms3ds.common.core.web.domain.AjaxResult;
import com.ms3ds.common.core.utils.poi.ExcelUtil;
import com.ms3ds.common.core.web.page.TableDataInfo;

/**
 * 进尺数据Controller
 * 
 * @author zlw
 * @date 2025-09-21
 */
@RestController
@RequestMapping("/footage")
public class FootageController extends BaseController
{
    @Autowired
    private IFootageService footageService;

    /**
     * 查询进尺数据列表
     */
    @RequiresPermissions("deviceData:footage:list")
    @GetMapping("/list")
    public TableDataInfo list(Footage footage)
    {
        startPage();
        List<Footage> list = footageService.selectFootageList(footage);
        return getDataTable(list);
    }

    /**
     * 导出进尺数据列表
     */
    @RequiresPermissions("deviceData:footage:export")
    @Log(title = "进尺数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Footage footage)
    {
        List<Footage> list = footageService.selectFootageList(footage);
        ExcelUtil<Footage> util = new ExcelUtil<Footage>(Footage.class);
        util.exportExcel(response, list, "进尺数据数据");
    }

    /**
     * 获取进尺数据详细信息
     */
    @RequiresPermissions("deviceData:footage:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(footageService.selectFootageById(id));
    }

    /**
     * 新增进尺数据
     */
    @RequiresPermissions("deviceData:footage:add")
    @Log(title = "进尺数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Footage footage)
    {
        return toAjax(footageService.insertFootage(footage));
    }

    /**
     * 修改进尺数据
     */
    @RequiresPermissions("deviceData:footage:edit")
    @Log(title = "进尺数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Footage footage)
    {
        return toAjax(footageService.updateFootage(footage));
    }

    /**
     * 删除进尺数据
     */
    @RequiresPermissions("deviceData:footage:remove")
    @Log(title = "进尺数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(footageService.deleteFootageByIds(ids));
    }

    /**
     * 生成 1 条符合业务规则的测试数据
     * GET 或 POST 均可，无参数
     */
    @PostMapping("/generateFootageData")   // 也可 @GetMapping
    public R<Boolean> generateFootageData(){
        int res = footageService.addTestFootageDataWithRule();
        return R.ok(true);
    }

    /**
     * 获取指定矿山的进尺图表数据
     */
    @GetMapping("/chartData")
    public R<Map<String, Object>> getFootageChartData(@RequestParam("mineId") Long mineId) {
        return footageService.getFootageChartDataByMineId(mineId);
    }


}
